import java.util.Random;
import java.io.*;

public class DataGenerator
{
    public static void main(String[] args) throws Exception
    {
	if (args.length < 4)
	{
	    System.out.println("Usage: DataGenerator [distribution] [n] [location] [scale]\nwhere [distribution] should be one of N (normal), U (Uniform), P (Pareto), or E (Exponential), [n] should be the number of points to generate, and [location] and [scale] should be the desired values for the distribution.");
	    System.out.println("You can also optionally add 2 more parameters to generate multiple copies of each data set. The 5th will be the number of repetitions, and the sixth is a prefix for the filename.");
	    System.exit(0);
	}

	Random r = new Random();
	int n = Integer.parseInt(args[1]);
	double location = Double.parseDouble(args[2]);
	double scale = Double.parseDouble(args[3]);

	if (args.length == 4)
	{
	    System.out.println(n);
	    if (args[0].equals("U"))
		for (int i = 0; i < n; ++i)
		    System.out.println(location + scale * r.nextDouble());
	    if (args[0].equals("N"))
		for (int i = 0; i < n; ++i)
		    System.out.println(location + scale * r.nextGaussian());
	    if (args[0].equals("P"))
		for (int i = 0; i < n; ++i)
		    System.out.println(location / Math.pow(1.0 - r.nextDouble(), 1.0/scale));
	    if (args[0].equals("E"))
                for (int i = 0; i < n; ++i)
                    System.out.println(location - Math.log(1.0 - r.nextDouble()));
	}
	else
	{
	    int times = Integer.parseInt(args[4]);
	    String name = args[5];
	    for (int j = 0; j < times; ++j)
	    {
		BufferedWriter b = new BufferedWriter(new FileWriter(name + j + ".dat"));
		b.write(n + "\n");
		if (args[0].equals("U"))
		    for (int i = 0; i < n; ++i)
			b.write((location + scale * r.nextDouble()) + "\n");
		if (args[0].equals("N"))
		    for (int i = 0; i < n; ++i)
			b.write((location + scale * r.nextGaussian()) + "\n");
		if (args[0].equals("P"))
		    for (int i = 0; i < n; ++i)
			b.write((location / Math.pow(1.0 - r.nextDouble(), 1.0/scale)) + "\n");
		if (args[0].equals("E"))
                    for (int i = 0; i < n; ++i)
                        b.write((location + Math.log(1.0 - r.nextDouble())) + "\n");
		b.close();
	    }
	}
    }


}